﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Clipper.Model;
using System.ComponentModel;

namespace ClipperBaseUI.Chart
{
    /// <summary>
    /// ChartArea.xaml 的交互逻辑
    /// </summary>
    public partial class ChartArea :UserControl
    {
        public ChartArea()
        {
            InitializeComponent();
        }
        #region 变量

        Axis mAxisX = null;
        Axis mAxisY = null;
        CoordinateInfoEnum mCoordinateType = 0;//默认是X-Y
        List<Series> mSeriesCollection = null;

        #endregion

        #region 属性
        /// <summary>
        /// 获得或设置X轴
        /// </summary>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [Bindable(true)]
        public Axis AxisX
        {
            get
            {
                if (mAxisX == null)
                {
                    mAxisX = new Axis(this, AxisTypeName.X);
                }
                return mAxisX;
            }
            set
            {
                mAxisX = value;
            }
        }

        /// <summary>
        /// 获得或设置Y轴
        /// </summary>
        public Axis AxisY
        {
            get
            {
                if (mAxisY == null)
                {
                    mAxisY = new Axis(this, AxisTypeName.Y);
                }
                return mAxisY;
            }
            set
            {
                mAxisY = value;
            }
        }
        /// <summary>
        /// 坐标系类型(默认是X-Y)
        /// </summary>
        public CoordinateInfoEnum CoordinateType
        {
            get
            {
                return mCoordinateType;
            }
            set
            {
                mCoordinateType = value;
            }
        }
        /// <summary>
        /// 数据序列的集合
        /// </summary>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [Bindable(true)]
        public List<Series> SeriesCollection
        {
            get
            {
                if (mSeriesCollection == null)
                {
                    mSeriesCollection = new List<Series>();
                }
                return mSeriesCollection;
            }
            set
            {
                mSeriesCollection = value;
            }
        }
        public Canvas CvsAxisX
        {
            get
            {
                return cvsAxisX;
            }
            set
            {
                value = cvsAxisX;
            }
        }
        #endregion

        /// <summary>
        /// 建立坐标系
        /// </summary>
        public void CreateCoordinate()
        {
            switch (CoordinateType)  //不同类型的坐标系
            {
                case CoordinateInfoEnum.XY:
                    AxisX.CreateAxis();
                    AxisY.CreateAxis();
                    break;
                case CoordinateInfoEnum.LogXLogY:
                    AxisX.CreateAxisLog();
                    AxisY.CreateAxisLog();
                    break;
                case CoordinateInfoEnum.LogXY:
                    AxisX.CreateAxisLog();
                    AxisY.CreateAxis();
                    break;
                case CoordinateInfoEnum.XLogY:
                    AxisX.CreateAxis();
                    AxisY.CreateAxisLog();
                    break;
                default:
                    throw new NotImplementedException();
            }

        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
        }
        public void ClearDataArea()
        {
            DataArea.Children.Clear();
        }

        private void UserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            int a = 0;
        }
    }
}
